package mebp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import org.apache.log4j.Logger;

public class NodeReader {
	static Logger log = Logger.getLogger(NodeReader.class);

	public static MEBP fromFile(String fn) throws java.io.IOException {
		MEBP ret = new MEBP();
		File f=new File(fn);
		java.io.BufferedReader in=new BufferedReader(new FileReader(f));
		String line = in.readLine();
		int nodeId = 0;
		while (line != null) {
			if (line.length() < 1 || line.startsWith("#"))
				continue;
			String a[] = line.split(" ", 2);
			float x = Float.parseFloat(a[0]);
			float y = Float.parseFloat(a[1]);
			Node n = new Node(nodeId++, x, y);
			ret.add(n);
			line = in.readLine();
		}
		ret.update();
		log.trace("Just read in Dataset "+fn+" and created a new MEBP Problem, closing stream");
		in.close();
		return ret;
	}
	
	
}
